﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SampleControls {
    public partial class FormContentSerializationWithSmartTag : Form {
        #region Properties

        private ContentSerializationWithSmartTag _navigatorBase;

        private object _value;
        public object Value {
            get { return _value; }
        }

        #endregion

        #region Contructors

        public FormContentSerializationWithSmartTag() {
            InitializeComponent();
        }

        public FormContentSerializationWithSmartTag(ContentSerializationWithSmartTag navigatorBase) {
            InitializeComponent();
            this._navigatorBase = navigatorBase;
        }

        #endregion

        #region Event Handlers

        private void UtfprFormEagerLoadEditor_Load(object sender, EventArgs e) {
            grdComponents.Columns["EagerLoadColumn"].DataPropertyName = "IsEagerLoaded";
            grdComponents.Columns["EntityCollectionColumn"].DataPropertyName = "EntityCollectionName";
            fillDataGrid();
        }

        private void btnOK_Click(object sender, EventArgs e) {
            if (bsComponents.Current != null) {
                if (bsComponents.List.Count > 0) {
                    _value = bsComponents.List.Cast<IRelatedEndDescription>().ToArray();
                } else {
                    _value = null;
                }
            }
        }

        #endregion

        #region Private Methods

        private void fillDataGrid() {
            bsComponents.DataSource = typeof(IRelatedEndDescription);

            if (this._navigatorBase.RelatedEndDescriptions == null || this._navigatorBase.RelatedEndDescriptions[0] == null) {
                var lstComponents = new List<IRelatedEndDescription>();

                lstComponents.Add(new RelatedEndDescription(false, "testeA"));
                lstComponents.Add(new RelatedEndDescription(false, "testeB"));
                lstComponents.Add(new RelatedEndDescription(false, "testeC"));

                bsComponents.DataSource = lstComponents;

                if (lstComponents.Count == 0) {
                    MessageBox.Show("No EntityCollection found.");
                }
            } else {
                bsComponents.DataSource = this._navigatorBase.RelatedEndDescriptions.ToList();
            }
        }

        #endregion
    }
}
